/*
 * Lab.fx
 *
 * Created on Nov 18, 2009, 12:42:56 AM
 */

package GraphsWindowPackage.LabPackage;
import GraphsWindowPackage.Entry;

/**
 * @author quang
 */

public class Lab extends Entry {
    public var timeSeries: Float[] = null;
    public var labValSeq: Float[] = null;

    public var ctgTimeSeq: Float[] = null;  //time sequence for categorical labs
    public var ctgLabValSeq: String[] = null;   //categorical labs values sequence

    public var rangeMin: Float = 0;   //min of normal lab value range
    public var rangeMax: Float = 100;   //max of normal lab value range

    public var lowerBound: Float = 0;
    public var upperBound: Float = 100;
    public var yStep: Float = 10;
    
    public var unit: String = "";

    public override function createEntryInTimeRange(minTime: Float, maxTime: Float): Lab {
        //if minTime <= maxTime then return those data points between these times
        if (minTime > maxTime) {
            return null;
        }
        else {
            var timeSeries: Float[] = null;
            var labValSeq: Float[] = null;
            var ctgTimeSeq: Float[] = null;
            var ctgLabValSeq: String[] = null;

            for (i in [0..sizeof this.timeSeries - 1]) {
                if (this.timeSeries[i] >= minTime and this.timeSeries[i] <= maxTime) {
                    insert this.timeSeries[i] into timeSeries;
                    insert this.labValSeq[i] into labValSeq;
                }
            }

            for (i in [0..sizeof this.ctgTimeSeq - 1]) {
                if (this.ctgTimeSeq[i] >= minTime and this.ctgTimeSeq[i] <= maxTime) {
                    insert this.ctgTimeSeq[i] into ctgTimeSeq;
                    insert this.ctgLabValSeq[i] into ctgLabValSeq;
                }
            }
            return Lab {
                name: this.name
                unit: this.unit
                rangeMin: this.rangeMin
                rangeMax: this.rangeMax
                lowerBound: this.lowerBound
                upperBound: this.upperBound
                yStep: this.yStep

                timeSeries: timeSeries
                labValSeq: labValSeq
                ctgTimeSeq: ctgTimeSeq
                ctgLabValSeq: ctgLabValSeq
            }
        }
    }    
}
